home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / BOSS_SUP.ARJ / WN_FRMGE.C < prev    next >
C/C++ Source or Header  |  1992-03-05  |  13KB  |  317 lines

  1. /*
  2. ** The Window BOSS's Data Clerk
  3. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  4. ** All rights reserved.
  5. **
  6. ** wn_frmget - Get (read) data entry form
  7. **
  8. ** Copyright (c) 1988 - Philip A. Mongelluzzo
  9. ** All rights reserved.
  10. **
  11. */
  12.  
  13. #include "winboss.h"                    /* standard stuff */
  14.  
  15. /*
  16. *************
  17. * wn_frmget *
  18. *************
  19. */
  20.  
  21. /*
  22. ** wn_frmget(frm)
  23. **
  24. **    int     nfields - number of fields in form.
  25. **
  26. ** RETURNS:
  27. **
  28. **    TRUE  - indicating all fields of the form in question have been
  29. **            fetched and verified (where required).
  30. **
  31. **    ESC_CODE - indicating ESCape was pressed and form processing
  32. **            was terminated.
  33. **
  34. **      or
  35. **
  36. **    Never Returns!!
  37. **
  38. ** NOTES:
  39. **
  40. **    This code can be used as is or can be customized to suite each
  41. **    applications need.  The section to customize is at the tail end
  42. **    of this file.  As distributed, logic diplays all prompts and
  43. **    display fields, positions to the first field, performs data
  44. **    entry on a field by field basis from the first to the last
  45. **    (allowing editing along the way), asks for a confirmation to
  46. **    accept the fields on the form after the last field is entered,
  47. **    either accepts the form or drops into edit mode for all the
  48. **    fields on the form starting at the first field.
  49. **
  50. **    wn_frmget will not return until all data has been entered and
  51. **    verified (where required).
  52. **
  53. **    This routine must be called after wn_frmopn, and before wn_frmcls.
  54. **
  55. */
  56.  
  57. /*
  58. *************
  59. * wn_frmget *
  60. *************
  61. */
  62.  
  63. #define FLD frm[indx]                   /* some shorthand */
  64.  
  65. wn_frmget(frm)                          /* input form processor */
  66. WIFORM frm;                             /* array of field pointers */
  67. {
  68. int indx;                               /* input field index */
  69. int rv;                                 /* wn_g???'s return value */
  70. int c;                                  /* scratch */
  71. WINDOWPTR wn;                           /* my OWN window */
  72.  
  73. static char *msg = "[Press ENTER to Accept, any other key to Edit]";
  74.  
  75.   wni_frmflg = TRUE;                    /* set initial state */
  76.                                         /* to display only */
  77.  
  78. begin:
  79.   indx = 0;                             /* reset index */
  80.   while(TRUE) {                         /* fetch input fields */
  81.     if(!FLD->fcode) break;              /* all done */
  82.     switch (FLD->fcode) {               /* based on function code */
  83.       case GDATE:
  84.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  85.           wns_ierr("wm_frmget@GDATE");
  86.         rv = wns_gfrm2(frm,indx,GDATE);
  87.         break;
  88.       case GEDATE:
  89.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  90.           wns_ierr("wm_frmget@GEDATE");
  91.         rv = wns_gfrm2(frm,indx,GEDATE);
  92.         break;
  93.       case GTIME:
  94.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  95.           wns_ierr("wm_frmget@GTIME");
  96.         rv = wn_gtime(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  97.                       FLD->col, FLD->prmpt,
  98.                       FLD->atrib, FLD->fill, FLD->v1.vip, FLD->v2.vip,
  99.                       FLD->v3.vip, FLD->v4.vcp,
  100.                       FLD->v5.vcp,FLD->v6.vcp);
  101.         break;
  102.       case GINT:
  103.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  104.           wns_ierr("wm_frmget@GINT");
  105.         rv = wn_gint(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  106.                      FLD->col, FLD->prmpt,
  107.                      FLD->atrib, FLD->fill, FLD->v1.vip, FLD->v2.vi,
  108.                      FLD->v3.vi, FLD->v4.vi, FLD->v5.vcp,
  109.                      FLD->v6.vcp,FLD->v7.vcp);
  110.         break;
  111.       case GUINT:
  112.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  113.           wns_ierr("wm_frmget@GUINT");
  114.         rv = wn_guint(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  115.                       FLD->col, FLD->prmpt,
  116.                       FLD->atrib, FLD->fill, FLD->v1.vuip, FLD->v2.vi,
  117.                       FLD->v3.vui, FLD->v4.vui, FLD->v5.vcp,
  118.                       FLD->v6.vcp,FLD->v7.vcp);
  119.         break;
  120.       case GLONG:
  121.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  122.           wns_ierr("wm_frmget@GLONG");
  123.         rv = wn_glong(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  124.                       FLD->col, FLD->prmpt,
  125.                       FLD->atrib, FLD->fill, FLD->v1.vlp, FLD->v2.vi,
  126.                       FLD->v3.vl, FLD->v4.vl, FLD->v5.vcp,
  127.                       FLD->v6.vcp,FLD->v7.vcp);
  128.         break;
  129.       case GULONG:
  130.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  131.           wns_ierr("wm_frmget@GULONG");
  132.         rv = wn_gulong(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  133.                       FLD->col, FLD->prmpt,
  134.                       FLD->atrib, FLD->fill, FLD->v1.vulp, FLD->v2.vi,
  135.                       FLD->v3.vul, FLD->v4.vul, FLD->v5.vcp,
  136.                       FLD->v6.vcp,FLD->v7.vcp);
  137.         break;
  138.       case GFLOAT:
  139.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  140.           wns_ierr("wm_frmget@GFLOAT");
  141.         rv = wn_gfloat(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  142.                        FLD->col, FLD->prmpt,
  143.                        FLD->atrib, FLD->fill, FLD->v1.vfp, FLD->v2.vi,
  144.                        FLD->v3.vi, FLD->v4.vf, FLD->v5.vf, FLD->v6.vcp,
  145.                        FLD->v7.vcp,FLD->v8.vcp);
  146.         break;
  147.       case GDOUBL:
  148.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  149.           wns_ierr("wm_frmget@GDOUBL");
  150.         rv = wn_gdouble(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  151.                        FLD->col, FLD->prmpt,
  152.                        FLD->atrib, FLD->fill, FLD->v1.vdp, FLD->v2.vi,
  153.                        FLD->v3.vi, FLD->v4.vd, FLD->v5.vd, FLD->v6.vcp,
  154.                        FLD->v7.vcp,FLD->v8.vcp);
  155.         break;
  156.       case GPHONE:
  157.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  158.           wns_ierr("wm_frmget@GPHONE");
  159.         rv = wn_gphone(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  160.                        FLD->col, FLD->prmpt,
  161.                        FLD->atrib, FLD->fill, FLD->v1.vip, FLD->v2.vip,
  162.                        FLD->v3.vip, FLD->v4.vcp,
  163.                        FLD->v5.vcp,FLD->v6.vcp);
  164.         break;
  165.       case GSSN:
  166.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  167.           wns_ierr("wm_frmget@GSSN");
  168.         rv = wn_gssn(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  169.                        FLD->col, FLD->prmpt,
  170.                        FLD->atrib, FLD->fill, FLD->v1.vip, FLD->v2.vip,
  171.                        FLD->v3.vip, FLD->v4.vcp,
  172.                        FLD->v5.vcp,FLD->v6.vcp);
  173.         break;
  174.       case GTEXT:
  175.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  176.           wns_ierr("wm_frmget@GTEXT");
  177.         rv = wn_gtext(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  178.                       FLD->col, FLD->prmpt,
  179.                       FLD->atrib, FLD->fill, FLD->v1.vi, FLD->v2.vcp,
  180.                       FLD->v3.vcp,FLD->v4.vcp);
  181.         break;
  182.       case GUTEXT:
  183.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  184.           wns_ierr("wm_frmget@GUTEXT");
  185.         rv = wn_gutext(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  186.                       FLD->col, FLD->prmpt,
  187.                       FLD->atrib, FLD->fill, FLD->v1.vi, FLD->v2.vcp,
  188.                       FLD->v3.vcp,FLD->v4.vcp);
  189.         break;
  190.       case GLTEXT:
  191.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  192.           wns_ierr("wm_frmget@GLTEXT");
  193.         rv = wn_gltext(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  194.                       FLD->col, FLD->prmpt,
  195.                       FLD->atrib, FLD->fill, FLD->v1.vi, FLD->v2.vcp,
  196.                       FLD->v3.vcp,FLD->v4.vcp);
  197.         break;
  198.       case GATEXT:
  199.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  200.           wns_ierr("wm_frmget@GATEXT");
  201.         rv = wn_gatext(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  202.                       FLD->col, FLD->prmpt,
  203.                       FLD->atrib, FLD->fill, FLD->v1.vi, FLD->v2.vucp,
  204.                       FLD->v3.vucp,FLD->v4.vucp);
  205.         break;
  206.       case GMLTEX:
  207.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  208.           wns_ierr("wm_frmget@GMLTEX");
  209.         rv = wn_gmltext(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  210.                       FLD->col, FLD->prmpt,
  211.                       FLD->atrib, FLD->fill, FLD->v1.vi, FLD->v2.vi,
  212.                       FLD->v3.vacp,FLD->v4.vcp,FLD->v5.vcp);
  213.         break;
  214.       case GBOOL:
  215.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  216.           wns_ierr("wm_frmget@GBOOL");
  217.         rv = wn_gbool(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  218.                       FLD->col, FLD->prmpt,
  219.                       FLD->atrib, FLD->fill, FLD->v1.vip, FLD->v2.vcp,
  220.                       FLD->v3.vcp,FLD->v4.vcp);
  221.         break;
  222.       case DTEXT:                       /* display text */
  223.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  224.           wns_ierr("wm_frmget@DTEXT");
  225.         rv = wn_dtext(XEQ,NFRM,NFLD,FLD->wn, FLD->row, FLD->col, FLD->prmpt);
  226.         break;
  227.       case GPWORD:
  228.         if(FLD->pself != (char *)FLD)   /* corrupted memory check */
  229.           wns_ierr("wm_frmget@GPWORD");
  230.         rv = wn_gpword(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  231.                       FLD->col, FLD->prmpt,
  232.                       FLD->atrib, FLD->fill, FLD->v1.vi, FLD->v2.vcp,
  233.                       FLD->v3.vcp,FLD->v4.vcp);
  234.         break;
  235.     }                                   /* end switch(frm.code) */
  236.     if(rv != BKTAB && rv != UARROW)     /* previous field ?? */
  237.       indx++;                           /* no, just bump index */
  238.     else {                              /* previous field request */
  239.       indx--;                           /* decrement index */
  240.       while (FLD->fcode == DTEXT)       /* positioned at display text?? */
  241.         indx--;                         /* decrement past display text */
  242.       if(indx <= 0) indx = 0;           /* but dont be stupid! */
  243.     }
  244.     if(rv == ESC)                       /* Escape backout - ESC.001 */
  245.       return(ESC_CODE);                 /* Escape backout - ESC.001 */
  246.   }
  247.  
  248.   if(wni_frmflg) {                      /* first pass thru */
  249.     wni_frmflg = FALSE;                 /* displays prompts & data */
  250.     goto begin;                         /* now, lets *really* read */
  251.   }
  252.  
  253. /*************************************************************************
  254. *                                                                        *
  255. *                  CUSTOMIZE THE SECTION BELOW ONLY                      *
  256. *                                                                        *
  257. **************************************************************************/
  258.  
  259.                                         /* PRESS Return Stuff */
  260.   wn=wn_open(1000,(wni_mxrows-1),0,(int)strlen(msg),1,(RVIDEO),NVIDEO);
  261.   if(!wn) exit(1);
  262.   wn_puts(wn,0,0,msg);                  /* display message */
  263.   c = v_getch() & 0xff;                 /* fetch response */
  264.   wn_close(wn);                         /* make message go away */
  265.   if(c == CR)                           /* ENTER ?? */
  266.     return(TRUE);                       /* return if so */
  267.   if(c == ESC)                          /* Escape Backout - ESC.001 */
  268.     return(ESC_CODE);                   /* Escape Backout - ESC.001 */
  269.   else                                  /* else edit the */
  270.     goto begin;                         /* form ! */
  271. }
  272.  
  273.  
  274. #ifdef COMMENTS
  275. /*
  276. ** The following function was added in 1992 to workaround problems that 
  277. ** TopSpeed C had in compiling WN_FRMGET().  This workaround solved what
  278. ** ever problem the optimize had in sorting wn_frmget() out!
  279. **
  280. ** Sorry for the kludge.
  281. **
  282. */
  283. #endif
  284.  
  285. /*
  286. *************
  287. * wns_gfrm2 *
  288. *************
  289. */
  290.  
  291. wns_gfrm2(frm,indx,code)                /* OVERFLOW FUNCTION */
  292. WIFORM frm;
  293. int indx, code;
  294. {
  295. int rv;
  296.   switch (code) {
  297.     case GDATE:
  298.         rv = wn_gdate(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  299.                       FLD->col, FLD->prmpt,
  300.                       FLD->atrib, FLD->fill, FLD->v1.vip, FLD->v2.vip,
  301.                       FLD->v3.vip, FLD->v4.vcp,
  302.                       FLD->v5.vcp,FLD->v6.vcp);
  303.         break;
  304.     case GEDATE:
  305.         rv = wn_gdate(XEQ,NFRM,NFLD,FLD->wn, FLD->row,
  306.                       FLD->col, FLD->prmpt,
  307.                       FLD->atrib, FLD->fill, FLD->v1.vip, FLD->v2.vip,
  308.                       FLD->v3.vip, FLD->v4.vcp,
  309.                       FLD->v5.vcp,FLD->v6.vcp);
  310.         break;
  311.   }
  312.   return(rv);
  313. }
  314.  
  315.  
  316. /* End */
  317.